package com.example.tests;

public class ContactData implements Comparable<ContactData> {
	
	private String firstname;
	private String lastname;
	private String email;
	private String email2;
	private String mobilephone;
	private String workphone;
	private String group;
	private BirthdayDateData birthdayDate = new BirthdayDateData();
	private AddressData homeAddressData = new AddressData();
	private AddressData secondAddressData = new AddressData();

	public ContactData() {
	}

	@Override
	public String toString() {
		return "ContactData [firstname=" + firstname + " lastname=" + lastname +  " email=" + email + "]";
	}

	@Override
	public int hashCode() {
		//final int prime = 31;
		int result = 1;
		//result = prime * result + ((email == null) ? 0 : email.hashCode());
		//result = prime * result
		//		+ ((firstname == null) ? 0 : firstname.hashCode());
		//result = prime * result
		//		+ ((lastname == null) ? 0 : lastname.hashCode());
		//result = prime * result
		//		+ ((mobilephone == null) ? 0 : mobilephone.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ContactData other = (ContactData) obj;
		if (email == null) {
			if (other.email != null)
				return false;
		} else if (!email.equals(other.email))
			return false;
		if (firstname == null) {
			if (other.firstname != null)
				return false;
		} else if (!firstname.equals(other.firstname))
			return false;
		if (lastname == null) {
			if (other.lastname != null)
				return false;
		} else if (!lastname.equals(other.lastname))
			return false;
		if (mobilephone == null) {
			if (other.mobilephone != null)
				return false;
		} else if (!mobilephone.equals(other.mobilephone))
			return false;
		return true;
	}

	@Override
	public int compareTo(ContactData other) {
		return this.firstname.toLowerCase().compareTo(other.firstname.toLowerCase()) + 
				this.lastname.toLowerCase().compareTo(other.lastname.toLowerCase()) + 
				this.email.toLowerCase().compareTo(other.email.toLowerCase()) +
				this.mobilephone.toLowerCase().compareTo(other.mobilephone.toLowerCase());
	}

	public ContactData withFirstname(String firstname) {
		this.firstname = firstname;
		return this;
	}
	
	public ContactData withLastname(String lastname) {
		this.lastname = lastname;
		return this;
	}
	
	public ContactData withEmail(String email) {
		this.email = email;
		return this;
	}
	
	public ContactData withEmail2(String email2) {
		this.email2 = email2;
		return this;
	}
	
	public ContactData withMobilePhone(String mobilephone) {
		this.mobilephone = mobilephone;
		return this;
	}
	
	public ContactData withWorkPhone(String workphone) {
		this.workphone = workphone;
		return this;
	}
	
	public ContactData withHomeAddress(String homeAddress) {
		this.homeAddressData.withAddress(homeAddress);
		return this;
	}
	
	public ContactData withHomePhone(String homePhone) {
		this.homeAddressData.withPhone(homePhone);
		return this;
	}
	
	public ContactData withSecondAddress(String secondAddress) {
		this.secondAddressData.withAddress(secondAddress);
		return this;
	}
	
	public ContactData withSecondPhone(String secondPhone) {
		this.secondAddressData.withPhone(secondPhone);
		return this;
	}
	
	public ContactData withBirthdayYear(String birthdayYear) {
		this.birthdayDate.withByear(birthdayYear);
		return this;
	}
	
	public ContactData withBirthdayMonth(String birthdayMonth) {
		this.birthdayDate.withBmonth(birthdayMonth);
		return this;
	}
	
	public ContactData withBirthdayDay(String birthdayDay) {
		this.birthdayDate.withBday(birthdayDay);
		return this;
	}
	
	public ContactData withGroup(String group) {
		this.group = group;
		return this;
	}

	public String getFirstname() {
		return firstname;
	}

	public String getLastname() {
		return lastname;
	}

	public String getEmail() {
		return email;
	}

	public String getEmail2() {
		return email2;
	}

	public String getMobilephone() {
		return mobilephone;
	}

	public String getWorkphone() {
		return workphone;
	}

	public String getGroup() {
		return group;
	}

	public BirthdayDateData getBirthdayDate() {
		return birthdayDate;
	}

	public AddressData getHomeAddressData() {
		return homeAddressData;
	}

	public AddressData getSecondAddressData() {
		return secondAddressData;
	}
}